package com.doubao.device.controller;

import com.doubao.common.result.Result;
import com.doubao.device.dto.CategoryDTO;
import com.doubao.device.dto.request.CreateCategoryRequest;
import com.doubao.device.dto.request.UpdateCategoryRequest;
import com.doubao.device.service.DeviceCategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/device/category")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "智能体分类管理", description = "智能体分类相关接口")
public class DeviceCategoryController {

    private final DeviceCategoryService categoryService;

    @PostMapping
    @Operation(summary = "创建分类", description = "创建一个新的智能体分类")
    public Result<CategoryDTO> createCategory(@Validated @RequestBody CreateCategoryRequest request) {
        return categoryService.createCategory(request);
    }

    @PutMapping
    @Operation(summary = "更新分类", description = "更新智能体分类信息")
    public Result<CategoryDTO> updateCategory(@Validated @RequestBody UpdateCategoryRequest request) {
        return categoryService.updateCategory(request);
    }

    @DeleteMapping("/{categoryId}")
    @Operation(summary = "删除分类", description = "删除指定的智能体分类")
    public Result<Void> deleteCategory(
            @Parameter(description = "分类ID") @PathVariable Long categoryId) {
        return categoryService.deleteCategory(categoryId);
    }

    @GetMapping("/{categoryId}")
    @Operation(summary = "获取分类详情", description = "获取指定分类的详细信息")
    public Result<CategoryDTO> getCategoryDetail(
            @Parameter(description = "分类ID") @PathVariable Long categoryId) {
        return categoryService.getCategoryDetail(categoryId);
    }

    @GetMapping("/list")
    @Operation(summary = "获取所有分类", description = "获取所有智能体分类")
    public Result<List<CategoryDTO>> getAllCategories() {
        return categoryService.getAllCategories();
    }

    @GetMapping("/enabled")
    @Operation(summary = "获取启用的分类", description = "获取所有启用状态的智能体分类")
    public Result<List<CategoryDTO>> getEnabledCategories() {
        return categoryService.getEnabledCategories();
    }

    @PutMapping("/{categoryId}/sort")
    @Operation(summary = "更新分类排序", description = "更新指定分类的排序值")
    public Result<Void> updateSortOrder(
            @Parameter(description = "分类ID") @PathVariable Long categoryId,
            @Parameter(description = "排序值") @RequestParam Integer sortOrder) {
        return categoryService.updateSortOrder(categoryId, sortOrder);
    }

    @PutMapping("/{categoryId}/status")
    @Operation(summary = "更新分类状态", description = "更新指定分类的状态")
    public Result<Void> updateStatus(
            @Parameter(description = "分类ID") @PathVariable Long categoryId,
            @Parameter(description = "状态 1:启用 0:禁用") @RequestParam Integer status) {
        return categoryService.updateStatus(categoryId, status);
    }
} 